package com.lagou.filter;

import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.io.IOException;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;

@Order(1)
@Component
@WebFilter(filterName = "requestFilter", urlPatterns = "/*")
public class RequestFilter  implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("--------------------------STARTED--------------------------------");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        try {
            WebRequestHolder.setting(servletRequest);
            filterChain.doFilter(servletRequest,servletResponse);
        } finally {
            WebRequestHolder.remove();
        }
    }

    @Override
    public void destroy() {

    }
}
